close all;
clear all;

blank_row = 3; %blank rows in directory

% Extract images
imagefilesa = dir('/Users/adambindas/Dropbox/Documents/Koppes Lab/Programs/agg a-Syn Quantification/Att 4 01-23-21/Live imaging mono');      

% Define for loop size
nfiles = length(imagefilesa)-blank_row;
avg.int = zeros(nfiles,1);
max.int = zeros(nfiles,1);
perc90  = zeros(nfiles,1);
perc80  = zeros(nfiles,1);
perc75  = zeros(nfiles,1);
perc50  = zeros(nfiles,1);
perc25  = zeros(nfiles,1);
perc20  = zeros(nfiles,1);
perc10  = zeros(nfiles,1);

% For loop of calculating average intensity
for ii=1:nfiles
   a_name = imagefilesa(ii+blank_row).name; % Extract filename
   a_col = imread(a_name); % Import image
   a = rgb2gray(a_col); % Grayscale image
   
   % Calculate Percentiles of Average Intensity
   maxer = prctile(a,100,'all');
   max.int(ii) = maxer;
   percVal90 = prctile(a,90,'all');
   perc90(ii) = percVal90;
   percVal80 = prctile(a,80,'all');
   perc80(ii) = percVal80;
   percVal75 = prctile(a,75,'all');
   perc75(ii) = percVal75;
   percVal50 = prctile(a,50,'all');
   perc50(ii) = percVal50;
   percVal25 = prctile(a,25,'all');
   perc25(ii) = percVal25;
   percVal20 = prctile(a,20,'all');
   perc20(ii) = percVal20;
   percVal10 = prctile(a,10,'all');
   perc10(ii) = percVal10;
   
   % Average Intensity Calculation
   AvgInt = mean2(a);
   avg.int(ii) = AvgInt;
end 

% Create output matrix
rownames = transpose({imagefilesa(blank_row+1:blank_row+nfiles).name});
live_dat = table(rownames,max.int,avg.int,perc90,perc80,perc75,perc50,perc25,perc20,perc10,'VariableNames',{'rownammes','max.int', 'avg.int', 'perc90', 'perc80', 'perc75', 'perc50', 'perc25', 'perc20', 'perc10'});
writetable(live_dat) 